//2009/09/03 23:43:30
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class Twain
{
public:
    string getNewSpelling(int year, string phrase)
    {
		phrase = " " + phrase;
        if (year > 0)
        {
            subs(phrase, " x", " z");
			subs(phrase, "x", "ks");
            cout << "1: " << phrase << endl;
        }
        if (year > 1)
        {
			/*
            for (int i=0; i<phrase.size(); i++)
                if (phrase[i]=='y')
                    phrase[i] = 'i';
            */
			subs(phrase, "y", "i");
			cout << "2: " << phrase << endl;
        }
        if (year > 2)
        {
            //int pos;
            //while ((pos = phrase.find("ce")) != string::npos) phrase.replace(pos, 2, "se");
            //while ((pos = phrase.find("ci")) != string::npos) phrase.replace(pos, 2, "si");
            subs(phrase, "ce", "se");
			subs(phrase, "ci", "si");
			cout << "3: " << phrase << endl;
        }
        if (year > 3)
        {
            //int pos;
            //while ((pos = phrase.find("ck") )!= string::npos) phrase.replace(pos, 2, "k");
            while(subs(phrase, "ck", "k"));
			cout << "4: " << phrase << endl;
        }
        if (year > 4)
        {
            subs(phrase, " sch", " sk");
            //cout << "5: phrase: " << phrase << endl;
            //while ((pos = phrase.find("chr")) != string::npos) phrase.replace(pos, 3, "kr");
			subs(phrase, "chr", "kr");
			//cout << "5: phrase: " << phrase << endl;
            for (int i=0; i<phrase.size(); i++)
            {
                if (phrase[i] == 'c' && (i+1==phrase.size() || phrase[i+1] != 'h'))
                    phrase[i] = 'k';
            }
            cout << "5: " << phrase << endl;
        }
        if (year > 5)
        {
            //int pos;
			//while ((pos = phrase.find("kn")) != string::npos && (pos == 0 || phrase.substr(pos-1, 1) == " "))
			//	phrase.replace(pos, 2, "n");
			subs(phrase, " kn", " n");
			cout << "6: " << phrase << endl;
        }
        if (year > 6)
        {
			/*
            bool flag = false;
            while (!flag)
            {
                flag = true;
                string s;
                for (int i=0; i+1 < phrase.size(); i++)
                {
                    if (phrase[i] == phrase[i+1] && isconsonants(phrase[i]) && isconsonants(phrase[i+1]))
                    {
                        phrase.erase(phrase.begin() + i);
                        flag = false;
                        break;
                    }
                }
            }
			*/
			string s;
			for(int i=0; i<phrase.size();)
			{
				char c = phrase[i];
				s += c;
				if(isconsonants(c))
				{
					i++;
					for(; i<phrase.size();)
					{
						if(phrase[i] == c) i++;
						else break;
					}
				}
				else i++;
			}
			phrase = s;
            cout << "7: " << phrase << endl;
        }
        return phrase.substr(1);
    }
    bool isconsonants(char c)
    {
        if (c!='a' && c!='e' && c!='i' && c!='o' && c!='u' && c!=' ') return true;
        return false;
    }
	int subs(string& s, string x, string y)
	{
		string temp;
		int cnt = 0;
		for(int i=0; i<s.size(); i++)
		{
			if(s.substr(i, x.size()) == x)
			{
				cnt ++;
				temp += y;
				i += x.size() - 1;
			}
			else temp += s[i];
		}
		s = temp;
		return cnt;
	}
};
